<script>
	import {
		getWxJsApis,
		h5AutoLogin
	} from "@/http/api/user/user.js"
	import Cache from '@/utils/cache'
	import jweixin from 'weixin-js-sdk';
	export default {
		onLaunch: function() {

			let access_token = Cache.get('access_token');
			if (this.$route.query.extendCode) {
				Cache.set('extendCode', this.$route.query.extendCode);
			}
			this.globalData.globalShare()
		},
		onShow: function() {
			console.log(123)
			// #ifdef APP-PLUS
			uni.hideTabBar()
			// #endif
			console.log('App Show')
		},
		globalData: {
			ossurl: 'https://oss.lailalaila.cn/',
			// ossurl: 'https://oss.starbounce.cn/', 
			initJssdk(callback, fail) {
				getWxJsApis(window.location.href)
					.then(res => {
						if (res.code === 200) {
							let sdk = res.data;
							jweixin.config({
								debug: false,
								appId: sdk.appId,
								timestamp: sdk.timestamp,
								nonceStr: sdk.nonceStr,
								signature: sdk.signature,
								jsApiList: [
									'updateAppMessageShareData', //分享朋友
									'updateTimelineShareData', //分享朋友圈  
									'getLocation', //获取位置  
									'openLocation', //打开位置  
									'chooseWXPay', //微信支付    
								]
							});
							jweixin.ready(() => {
								callback(jweixin)
							});
							jweixin.error((err) => {
								if (fail) {
									fail(err);
								} else {
									console.error('微信JS-SDK配置失败:', err);
								}
							});
						} else {
							if (fail) {
								fail(new Error('获取微信JS-SDK配置失败'));
							} else {
								console.error('获取微信JS-SDK配置失败:', res);
							}
						}
					})
					.catch(error => {
						if (fail) {
							fail(error);
						} else {
							console.error('获取微信JS-SDK配置请求失败:', error);
						}
					});
			},
			globalShare: (isShare, title = '分享', link = window.location.href, desc = '内容', cb = () => {}, errorCb =
				() => {}) => {
				getApp().globalData.initJssdk((wx) => {
					let extendCode = Cache.get('extendCode');
					if (isShare) {
						//分享给朋友
						wx.updateAppMessageShareData({
							title: title,
							desc: desc,
							link: `${link}?extendCode=${extendCode}`,
							success: (res) => {
								cb(res)
							},
							cancel: (cancelMsg) => {
								errorCb(cancelMsg)
							}
						})
					} else {
						// 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容
						wx.updateTimelineShareData({
							title: title,
							link: link,
							success: (res) => {
								cb(res)
							},
							cancel: (cancelMsg) => {
								errorCb(cancelMsg)
							}
						})
					}

				})
			}
		}
	}
</script>

<style>
	@import './common/app.css';
	@import './static/style/thorui-extend.css';
	@import '@/style/free.css';
	@import '@/style/color.css';
	@import '@/style/size.css';
	@import '@/style/common.scss';
	uni-toast {
		z-index: 99999999 !important;
	}

	uni-modal {
		z-index: 99999 !important;
	}

	.uni-sample-toast {
		z-index: 99999999 !important;
		/* 根据实际情况进行调整 */
	}

	
</style>